﻿using BrnMall.Manager.Domain.AddressBook;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrnMall.Manager.Manager.AddressBook
{
    public class StaffExtendManager
    {
        static string TableName="crm_StaffExtend";
        public static bool Insert(StaffExtend model)
        {
            using (var db = new QDMallDatabase())
            {
                db.Insert(model);
            }
            return model.StaffId > 0;
        }
        public static int delete(int  id)
        {
            using (var db = new QDMallDatabase())
            {
                return db.Execute(string.Format("delete from {0} where Id={1}", TableName, id));
            }
        }

        public static bool Update(int id, string value)
        {
            int count = 0;
            using (var db = new QDMallDatabase())
            {
                count = db.Execute($"update {TableName} set value=@0 where id=@1", value, id);
            }
            return count > 0;
        }

        /// <summary>
        /// 获取欢迎语
        /// </summary>
        /// <param name="staffid"></param>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public static StaffExtend GetWelcomeTip(int staffid, int keyword)
        {
            using (var db = new QDMallDatabase())
            {
                string sql = string.Format("select * from {0} where staffId={1} and keyword={2}", TableName, staffid, keyword);
                return db.SingleOrDefault<StaffExtend>(sql);
            }
        }
        public static List<StaffExtend> GetWelcomeTipList(int staffid, int keyword)
        {
            using (var db = new QDMallDatabase())
            {
                string sql = string.Format("select * from {0} where staffId={1} and keyword={2}", TableName, staffid, keyword);
                return db.Fetch<StaffExtend>(sql);
            }
        }
    }
}